/*
 * Type-safe wrapper for WebGL in GWT.
 * 
 * Copyright (C) 2009 Hao Nguyen
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package gwt.g3d.client.texture;

import gwt.g3d.client.gl2.enums.PixelFormat;
import gwt.g3d.client.gl2.enums.PixelInternalFormat;
import gwt.g3d.client.gl2.enums.PixelType;
import gwt.g3d.client.gl2.enums.TextureParameterName;
import gwt.g3d.client.gl2.enums.TextureTarget;
import gwt.g3d.client.gl2.enums.TextureWrapMode;

import com.google.gwt.dom.client.CanvasElement;
import com.google.gwt.dom.client.ImageElement;
import com.google.gwt.dom.client.VideoElement;

/**
 * Represents a 2D texture.
 * 
 * @author hao1300@gmail.com
 */
public class Texture2D extends AbstractTexture {
  
  public Texture2D() {
    super(TextureTarget.TEXTURE_2D);
  }
  
  @Override
  public void setWrapMode(TextureWrapMode wrapMode) {
    setWrapMode(TextureParameterName.TEXTURE_WRAP_S, wrapMode);
    setWrapMode(TextureParameterName.TEXTURE_WRAP_T, wrapMode);
  }

  /**
   * Specifies a 2D image
   * Requires: {@link #bind()} must be called before using this method.
   * 
   * @param image
   */
  public void texImage(CanvasElement image) {
    gl.texImage2D(getTarget(), 0, PixelInternalFormat.RGBA, PixelFormat.RGBA,
       PixelType.UNSIGNED_BYTE,  image);
  }
  
  /**
   * Specifies a 2D image
   * Requires: {@link #bind()} must be called before using this method.
   * 
   * @param image
   */
  public void texImage(ImageElement image) {
    gl.texImage2D(getTarget(), 0, PixelInternalFormat.RGBA, PixelFormat.RGBA,
         PixelType.UNSIGNED_BYTE,  image);
  }
  
  /**
   * Specifies a 2D image
   * Requires: {@link #bind()} must be called before using this method.
   * 
   * @param image
   */
  public void texImage(VideoElement image) {
    gl.texImage2D(getTarget(), 0, PixelInternalFormat.RGBA, PixelFormat.RGBA,
         PixelType.UNSIGNED_BYTE,  image);
  }
  
  /**
   * Specifies a 2D image
   * Requires: {@link #bind()} must be called before using this method.
   * 
   * @param image
   */
  public void texSubImage(int xOffset, int yOffset, CanvasElement image) {
    gl.texSubImage2D(getTarget(), 0, xOffset, yOffset, PixelFormat.RGBA,
         PixelType.UNSIGNED_BYTE, image);
  }
  
  /**
   * Specifies a 2D image2
   * Requires: {@link #bind()} must be called before using this method.
   * 
   * @param image
   */
  public void texSubImage(int xOffset, int yOffset, ImageElement image) {
    gl.texSubImage2D(getTarget(), 0, xOffset, yOffset, PixelFormat.RGBA,
         PixelType.UNSIGNED_BYTE, image);
  }
  
  /**
   * Specifies a 2D image
   * Requires: {@link #bind()} must be called before using this method.
   * 
   * @param image
   */
  public void texSubImage(int xOffset, int yOffset, VideoElement image) {
    gl.texSubImage2D(getTarget(), 0, xOffset, yOffset, PixelFormat.RGBA,
         PixelType.UNSIGNED_BYTE, image);
  }
}
